<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue基础</title>
  <style>
    .active {
      color: #f00;
    }
  </style>
</head>

<body>
  <div id="app">
    <ul>
      <!-- 让谁多就for谁 -->
      <input @keydown.enter="addTodo" v-model="newTodo" type="text"> <button @click="addTodo">Add Todo</button>
      <!-- <li v-for="todo in todos">{{todo.text}} <button @click="removeTodo(todo.id)">X</button></li> -->
      <li @click=" toggleActive(todo)" v-for="(todo,index) in todos" :key="todo.id"
        :class="todo.isActive ?  'active' :''">
        {{todo.text}}
        <button @click="removeTodo(index)">X</button>
      </li>

    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.8/dist/vue.js"></script>
  <script>
    // 给每个 todo 对象一个唯一的 id
    let id = 0
    const app = new Vue({
      el: '#app',
      data: {
        newTodo: '',
        todos: [
          { isActive: false, id: id++, text: 'Learn HTML' },
          { isActive: false, id: id++, text: 'Learn JavaScript' },
          { isActive: false, id: id++, text: 'Learn Vue' }
        ]
      },
      methods: {
        addTodo() {
          this.todos.push({ isActive: false, id: id++, text: this.newTodo })
          this.newTodo = ''
        },
        // removeTodo(i) {
        //   this.todos.splice(i, 1)
        // },
        removeTodo(id) {
          this.todos = this.todos.filter(item => {
            return item.id != id
          })
        },
        toggleActive(obj) {
          obj.isActive = !obj.isActive
        }
      }
    });

    const arr = [1, 2, 3]
    let arr2 = arr.slice(1, 2)
    console.log(arr2);

  </script>

</body>

</html>